import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { GBox } from "../../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { BossAreaInfo } from "../../../model/BossAreaInfo";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { BossAreaListItem } from "./BossAreaListItem";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
//class BossAreaList
    
    export  class BossAreaList /* flash.display.Sprite */
    {
        constructor()
        {
            if (BossAreaList._instance) 
            {
                throw new Error("BossAreaList is single");
            }
            else 
            {
                
                mouseEnabled = false;
                this._bg = ResouceConst.getScaleBitmap("ToolTipBg");
                addChild(this._bg);
                this._bossList = new GBox();
                this._bossList.direction = GBoxDirection.VERTICAL;
                this._bossList.x = 5;
                this._bossList.y = 7;
                addChild(this._bossList);
                BossAreaList._instance = this;
            }
            return;
        }

        public updateData(arg1: BossAreaInfo): void
        {
            var loc1=0;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            var loc7=null;
            this.dispose();
            this._bossAreaInfo = arg1;
            var loc2=arg1.boss.length;
            while (loc1 < loc2) 
            {
                if ((loc3 = arg1.boss[loc1]) != null) 
                {
                    loc5 = 0;
                    loc6 = loc3.bosses.length;
                    while (loc5 < loc6) 
                    {
                        loc7 = loc3.bosses[loc5];
                        (loc4 = ObjectPool.getObject(BossAreaListItem)).updateData(loc7, loc3);
                        this._bossList.addChild(loc4);
                        ++loc5;
                    }
                }
                ++loc1;
            }
            this._bossList.invalidate();
            this._bg.width = this.width + 10;
            this._bg.height = this.height + 10;
            return;
        }

        public dispose(): void
        {
            var loc1=null;
            if (parent != null) 
            {
                parent.removeChild(this);
            }
            this._bossAreaInfo = null;
            while (this._bossList.numChildren > 0) 
            {
                loc1 = this._bossList.removeChildAt(0) as BossAreaListItem;
                loc1.dispose();
                ObjectPool.disposeObject(loc1, BossAreaListItem);
            }
            return;
        }

        public /* override */ get width(): number
        {
            var loc1=0;
            var loc2=0;
            var loc4=null;
            var loc3=this._bossList.numChildren;
            while (loc2 < loc3) 
            {
                loc4 = this._bossList.getChildAt(loc2) as BossAreaListItem;
                if (loc1 < loc4.width) 
                {
                    loc1 = loc4.width;
                }
                ++loc2;
            }
            return loc1;
        }

        public /* override */ get height(): number
        {
            return this._bossList.numChildren * 19;
        }

        public static getInstance(): BossAreaList
        {
            if (!BossAreaList._instance) 
            {
                BossAreaList._instance = new BossAreaList();
            }
            return BossAreaList._instance;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_bossList: GBox;

        /* internal */ /* var */_bossAreaInfo: BossAreaInfo;

        /* internal */ static /* var */_instance: BossAreaList;
    }
